import app from '@system.app';
import window from '@ohos.window';
export default {
    data: {
        title: 'World',
        windowClass:null
    },
    onInit(){
        window.getTopWindow((err, data) => {
            if (err) {
                console.error('WindowPlugin failed to getTopWindow because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin success data : ' + JSON.stringify(data));
            this.windowClass = data;
        });
    },
    getTopWindow(){
        console.info('WindowPlugin success data : ' + JSON.stringify(this.windowClass));
    },
    setSystemBarProperties(){
        var statusBarColor = '#ff00ff';
        var navigationBarColor = '#00ff00';
        var navigationbar = {statusBarColor, navigationBarColor};
        this.windowClass.setSystemBarProperties(navigationbar, (err, data) => {
            if (err) {
                console.error('WindowPlugin failed to setSystemBarProperties because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin setSystemBarProperties success data : ' + JSON.stringify(data));
        });
    },
    getProperties(){
        // 这里参数位置感觉不对 原始写法(err,data)
        this.windowClass.getProperties((data, err) => {
            if (err) {
                console.error('WindowPlugin failed to getProperties because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin getProperties success data : ' + JSON.stringify(err));
        });
    },
    setBackgroundColor(){
        var color = '#00ff33';
        this.windowClass.setBackgroundColor(color, (err, data) => {
            if (err) {
                console.error('WindowPlugin failed to setBackgroundColor because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin setBackgroundColor success data : ' + JSON.stringify(data));
        });
    },
    setKeepScreenOn(){
        var isKeepScreenOn = true;
        this.windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => {
            if (err) {
                console.error('WindowPlugin failed to setKeepScreenOn because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin setKeepScreenOn success data : ' + JSON.stringify(data));
        });
    },
    setFullScreen(){
        var info = app.getInfo();
        console.log(JSON.stringify(info));
        var isFullScreen = true;
        this.windowClass.setFullScreen(isFullScreen, (err, data) => {
            if (err) {
                console.error('WindowPlugin failed to setFullScreen because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin setFullScreen success data : ' + JSON.stringify(data));
        });
    },
    setBrightness(){
        var info = app.getInfo();
        console.log(JSON.stringify(info));
        var brightness = 10;
        this.windowClass.setBrightness(brightness, (err, data) => {
            if (err) {
                console.error('WindowPlugin failed to setBrightness because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin setBrightness success data : ' + JSON.stringify(data));
        });
    },
    windowOn(){
        var type= 'keyboardHeightChange';
        this.windowClass.on(type, (err, data) => {
            if (err) {
                console.error('WindowPlugin failed to keyboardHeightChange because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin keyboardHeightChange success data : ' + JSON.stringify(data));
        });
    },
    windowOff(){
        var type= 'keyboardHeightChange';
        this.windowClass.off(type, (err, data) => {
            if (err) {
                console.error('WindowPlugin failed to keyboardHeightChange because ' + JSON.stringify(err));
                return;
            }
            console.info('WindowPlugin keyboardHeightChange success data : ' + JSON.stringify(data));
        });
    }




}
